package com.eeprint.web.controller.tenant;

import com.eeprint.common.utils.AjaxResult;
import com.eeprint.system.domain.tenant.TenantPrintJob;
import com.eeprint.system.domain.tenant.vo.TenantPrintJobMessage;
import com.eeprint.system.domain.tenant.vo.TenantWithPageVo;
import com.eeprint.system.service.tenant.TenantPrintJobService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wsen
 * @Date 2020/10/17 16:23
 * @Version 1.0
 */
@RestController
public class TenantPrintJobController {
    @Autowired
    TenantPrintJobService tenantPrintjobService;

    /**
     * @Author: wsen on 2020/10/19 11:46
     * @Description: 添加打印作业
     */
    @PostMapping("/tenant/auth/printjob/printfile")
    public AjaxResult printFile(@RequestBody TenantPrintJob tenantPrintJob){
        int result = tenantPrintjobService.addPrintJob(tenantPrintJob);
        if(result == 1){
            return AjaxResult.success();
        }
        return AjaxResult.systemError();
    }

    /**
     * @Author: wsen on 2020/10/19 16:54
     * @Description: 查看员工的打印作业信息
     */
    @PostMapping("/tenant/auth/printjob/list")
    public AjaxResult list(@RequestBody TenantWithPageVo tenantWithPageVo){
        /** 根据当前页码和每页显示的条数进行分页 */
        PageHelper.startPage(tenantWithPageVo.getPageNum(),tenantWithPageVo.getPageSize());
        /** 根据员工id找出所有的打印作业信息 */
        List<TenantPrintJobMessage> printJobMessages =
                tenantPrintjobService.list(tenantWithPageVo.getCreateUserId());
        PageInfo<TenantPrintJobMessage> pageInfo = new PageInfo<>(printJobMessages);
        //tenantPrintJobWithPageVo.setPrintJobPage(pageInfo);
        return AjaxResult.success(pageInfo);
    }
}
